package com.ruoyi.leaveManage.controller.teacher;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.leaveManage.bo.LeaveManageEditBo;
import com.ruoyi.leaveManage.bo.LeaveManageQueryBo;
import com.ruoyi.leaveManage.service.ILeaveManageService;
import com.ruoyi.leaveManage.vo.LeaveUserVo;
import com.ruoyi.leaveManage.vo.LeaveVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(value = "老师请假信息控制器", tags = {"老师请假信息管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/leavemanage/teacher")
public class TeacherLeaveController extends BaseController {

    @Autowired
    private final ILeaveManageService iLeaveManageService;

    /**
     * 查询请假信息列表
     */
    @ApiOperation("查询请假信息列表")
    @PreAuthorize("@ss.hasPermi('leava:teacher:list')")
    @GetMapping("/list")
    public TableDataInfo<LeaveUserVo> list(LeaveManageQueryBo bo) {
        startPage();
        List<LeaveUserVo> list = iLeaveManageService.collegeOrteacherQueryList(bo);

        return getDataTable(list);

    }

    /**
     * 查询请假报表
     */
    @ApiOperation("查询请假报表")
    @PreAuthorize("@ss.hasPermi('leava:teacher:reportFromList')")
    @Log(title = "查询请假报表", businessType = BusinessType.INSERT)
    @GetMapping("/reportFromList")
    public TableDataInfo<LeaveUserVo> reportFromList(LeaveManageQueryBo bo) {

        startPage();
        bo.setTimeSlot(1);
        List<LeaveUserVo> list = iLeaveManageService.getReportFromList(bo);

        return getDataTable(list);
    }

    /**
     * 获取请假信息详细信息
     */
    @ApiOperation("获取请假信息详细信息")
    @PreAuthorize("@ss.hasPermi('leava:teacher:query')")
    @GetMapping("/{leaveId}")
    public AjaxResult<LeaveVo> getInfo(@PathVariable("leaveId" ) Long leaveId) {
        return AjaxResult.success(iLeaveManageService.queryById(leaveId));
    }

    /**
     * 审核假条
     */
    @ApiOperation("审核假条")
    @PreAuthorize("@ss.hasPermi('leava:teacher:update')")
    @GetMapping("/updateApprove")
    public AjaxResult<Void> updateApprove(@PathVariable("leaveId" ) LeaveManageEditBo bo) {
        return toAjax(iLeaveManageService.updateApprove(bo) ? 1 : 0);
    }

}
